package com.ruoyi.web.core.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.region.Region;
import lombok.Data;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * 腾讯云上传参数
 *
 * @author chenchuan2
 * @date 2023-01-13 14:09:58
 */
@Component
@ConfigurationProperties(prefix = "wechat.cos")
@Data
public class CosConfig {
    /**
     * 腾讯云控制台项目配置secretId
     */
    private String secretId = "";

    /**
     * 腾讯云控制台项目配置secretKey
     */
    private String secretKey = "";

    /**
     * 存储桶地域
     */
    private String region = "";

    /**
     * 存储桶名称
     */
    private String bucketName = "";

    @Bean
    @ConditionalOnMissingBean(COSClient.class)
    public COSClient cosClient() {

        COSCredentials cred = new BasicCOSCredentials(getSecretId(), getSecretKey());
        ClientConfig clientConfig = new ClientConfig(new Region(getRegion()));
        COSClient cosClient = new COSClient(cred, clientConfig);

        return cosClient;

    }
}
